import Unauthorized from "@/components/Unauthorized/Unauthorized.vue";
import NotFound from "@/components/Unauthorized/NotFound.vue";

// 创建一个路由数组
const routes = [
  // Login route (common)
  {
    name: "login",
    path: "/login",
    component: () => import("@/components/Login/LoginIndex.vue"),
  },

  // Student routes
  {
    name: "学生首页",
    path: "/student",
    component: () => import("@/components/Main/Main.vue"),
    redirect: "/student/dashboard",
    isLink: true,
    children: [
      {
        name: "学生仪表盘",
        path: "dashboard",
        component: () => import("@/components/Home/Home.vue"),
      },
      {
        name: "植物信息-",
        path: "plant",
        component: () => import("@/components/Plant.vue"),
      },
      {
        name: "种植方式-",
        path: "plantMethod",
        component: () => import("@/components/PlantMethod.vue"),
      },
      {
        name: "植物分类-",
        path: "plantClassification",
        component: () => import("@/components/PlantClassification.vue"),
      },
      {
        name: "选择实验-",
        path: "project",
        component: () => import("@/components/Project/ProjectStudent.vue"),
      },
      {
        name: "我的实验-",
        path: "myProject",
        component: () => import("@/components/Project/MyProjectStudent.vue"),
      },
      {
        name: "实验进展-",
        path: "experiment",
        component: () => import("@/components/Project/Experiment.vue"),
      },
      {
        name: "文献检索-",
        path: "literature",
        component: () => import("@/components/Literature/Literature.vue"),
      },
      {
        name: "植物识别-",
        path: "plantRecognition",
        component: () =>
          import("@/components/PlantRecognition/PlantRecognition.vue"),
      },
      {
        name: "表型信息-",
        path: "phenotypicData",
        component: () =>
          import("@/components/PhenotypicData/PhenotypicData.vue"),
      },
      {
        name: "数据报表-",
        path: "setting",
        component: () => import("@/components/Setting/Setting.vue"),
      },
      {
        name: "学生植物AI助手",
        path: "plantAI",
        component: () => import("@/components/PlantAI/PlantAI.vue"),
      },
    ],
  },

  // Researcher (teacher) routes
  {
    name: "researcher-home",
    path: "/researcher",
    component: () => import("@/components/Main/ResearcherMain.vue"),
    isLink: true,
    children: [
      {
        name: "导师仪表盘",
        path: "dashboard",
        component: () => import("@/components/Home/Home.vue"),
      },
      {
        name: "植物管理",
        path: "plant",
        component: () => import("@/components/Plant.vue"),
      },
      {
        name: "用户管理",
        path: "user",
        component: () => import("@/components/User.vue"),
      },
      {
        name: "种植方式",
        path: "plantMethod",
        component: () => import("@/components/PlantMethod.vue"),
      },
      {
        name: "植物分类",
        path: "plantClassification",
        component: () => import("@/components/PlantClassification.vue"),
      },
      {
        name: "选择实验",
        path: "project",
        component: () => import("@/components/Project/Project.vue"),
      },
      {
        name: "订单详情",
        path: "orderDetail/:id",
        component: () => import("@/components/OrderDetail.vue"),
      },
      {
        name: "文献检索",
        path: "literature",
        component: () => import("@/components/Literature/Literature.vue"),
      },
      {
        name: "导师管理",
        path: "researcher",
        component: () => import("@/components/Researcher/Researcher.vue"),
      },
      {
        name: "学生管理",
        path: "student",
        component: () => import("@/components/Student/Student.vue"),
      },
      {
        name: "植物识别",
        path: "plantRecognition",
        component: () =>
          import("@/components/PlantRecognition/PlantRecognition.vue"),
      },
      {
        name: "表型信息",
        path: "phenotypicData",
        component: () =>
          import("@/components/PhenotypicData/PhenotypicData.vue"),
      },
      {
        name: "数据报表",
        path: "setting",
        component: () => import("@/components/Setting/Setting.vue"),
      },
      {
        name: "植物AI助手",
        path: "plantAI",
        component: () => import("@/components/PlantAI/PlantAI.vue"),
      },
    ],
  },

  // 无权限访问页面
  {
    path: "/unauthorized",
    name: "unauthorized",
    component: Unauthorized,
  },

  // 根路径重定向
  {
    path: "/",
    redirect: (to) => {
      const userType = localStorage.getItem("userType");
      if (!userType) return "/login";
      return userType === "student"
        ? "/student/dashboard"
        : "/researcher/dashboard";
    },
  },

  // 404页面
  {
    path: "/:pathMatch(.*)*",
    name: "not-found",
    component: NotFound,
  },
];

export default routes;
